package com.jxtc.enterprise.merchant.controller;

import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jxtc.enterprise.common.constants.OrderPaymentStatus;
import com.jxtc.enterprise.common.entity.Store;
import com.jxtc.enterprise.common.mapper.OrderMapper;
import com.jxtc.enterprise.common.mapper.StoreMapper;
import com.jxtc.enterprise.common.utils.Result;
import com.jxtc.enterprise.common.utils.ResultGenerator;
import com.jxtc.enterprise.common.vo.PaginationResponseVO;
import com.jxtc.enterprise.merchant.dto.*;
import com.jxtc.enterprise.merchant.service.MerchantStoreManageService;
import com.jxtc.enterprise.merchant.vo.*;
import com.jxtc.enterprise.employee.serviceImpl.JxOrderServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 商铺端 "数据" Tab 页相关接口
 */
@RestController
@RequestMapping("/jxtc/enterprise/merchant/statistic")
@RequiredArgsConstructor
@Slf4j
public class MerchantStatisticDataController {

    private final StoreMapper storeMapper;
    private final OrderMapper orderMapper;

    private final MerchantStoreManageService merchantStoreManageService;

    @ApiResponse(responseCode = "200", description = "code 为 200 时，data 字段为商户营业相关数据；code 为 400 时，message 字段返回错误提示信息，此时 data 字段为空")
    @Operation(summary = "17.1 查询从商户入驻平台到当前，商户的总营业额，总订单份数，售后订单份数", tags = "17. 商铺小程序数据页", operationId = "17.1")
    @PostMapping("/queryStoreSaleSummary")
    public Result<StoreSaleSummaryVO> queryStoreSaleSummary(@Valid @RequestBody StoreSummaryDTO dto) {
        String storeId = dto.getStoreId();
        log.info("/queryStoreSaleSummary, storeId: {}, phone: {}, startDate: {}, endDate: {}", storeId, dto.getPhone(), dto.getStartDate(), dto.getEndDate());
        if (StringUtils.hasText(storeId)) {
            // 如果前端传递过来的 storeId 不为空
            // 验证前端传递过来的店铺 ID 在数据库中是否存在
            validStoreIdAndPhone(storeId, dto.getPhone());
        } else {
            // 如果前端传递过来的 storeId 为空，则根据店主手机号获取该店铺的 ID
            storeId = merchantStoreManageService.queryStoreIdByMerchantPhone(dto.getPhone());
        }

        // 开始时间如果未传递，则默认为本月第一天
        String startTime = dto.getStartDate();
        if (dto.getStartDate() == null || dto.getStartDate().isEmpty()) {
            LocalDate today = LocalDate.now();
            LocalDate firstDayOfMonth = today.withDayOfMonth(1);

            startTime = firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }

        // 截至时间设置为当前日期的前一天
        String endTime = dto.getEndDate();
        if (dto.getEndDate() == null || dto.getEndDate().isEmpty()) {
            endTime = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }

        // 根据店铺 ID 查询店铺的营业相关数据
        StoreSaleSummaryDTO summaryDO = orderMapper.queryStoreSaleSummaryByStoreId(storeId, startTime, endTime);
        // 如果查询不到数据，默认全部返回 0
        if (summaryDO == null) {
            summaryDO = new StoreSaleSummaryDTO(0, 0, 0);
        }

        StoreSaleSummaryVO vo = new StoreSaleSummaryVO(
                summaryDO.getTotalMoney(),
                summaryDO.getTotalFoods(),
                summaryDO.getAfterSaleFoods(),
                startTime,
                endTime
        );
        log.info("/queryStoreSaleSummary, 接口返回: {}", vo);
        return ResultGenerator.genSuccessResult(vo);
    }

    @ApiResponse(responseCode = "200", description = "code 为 200 时，表示导出成功，并返回文件流；code 为 400 时，message 字段返回错误提示信息")
    @Operation(summary = "17.2 导出某一天或某几天的订单详情（有效订单和售后订单）", tags = "17. 商铺小程序数据页", operationId = "17.2")
    @PostMapping("/exportStoreOrders")
    public void exportStoreOrders(HttpServletResponse response, @Valid @RequestBody ExportStoreOrderDTO dto) {
        String storeId = dto.getStoreId();
        log.info("/exportStoreOrders, storeId: {}, phone: {}, startDate: {}, endDate: {}", storeId, dto.getPhone(), dto.getStartDate(), dto.getEndDate());
        if (StringUtils.hasText(storeId)) {
            // 如果前端传递过来的 storeId 不为空
            // 验证前端传递过来的店铺 ID 在数据库中是否存在
            validStoreIdAndPhone(storeId, dto.getPhone());
        } else {
            // 如果前端传递过来的 storeId 为空，则根据店主手机号获取该店铺的 ID
            storeId = merchantStoreManageService.queryStoreIdByMerchantPhone(dto.getPhone());
        }

        // 导出店铺的订单详情
        List<ExportStoreDailyDataDTO> dailyOrderDetailList = orderMapper.queryStoreOrderDetailByDateAndStoreId(storeId, dto.getStartDate(), dto.getEndDate());
        List<Map<String, Object>> data = new ArrayList<>();
        int totalCompletedFoodCount = 0;
        int totalCompletedStorePrice = 0;
        int totalAfterSaleFoodCount = 0;
        int totalAfterSaleStorePrice = 0;
        for (ExportStoreDailyDataDTO dailyOrderDetail : dailyOrderDetailList) {
            Map<String, Object> row = createRow(dailyOrderDetail);
            data.add(row);

            if (OrderPaymentStatus.COMPLETED.getValue() == dailyOrderDetail.getOrderStatus()) {
                totalCompletedFoodCount += dailyOrderDetail.getQuantity();
                totalCompletedStorePrice += dailyOrderDetail.getStorePrice();
            }

            if (OrderPaymentStatus.AFTER_SALE.getValue() == dailyOrderDetail.getOrderStatus()) {
                totalAfterSaleFoodCount += dailyOrderDetail.getQuantity();
                totalAfterSaleStorePrice += dailyOrderDetail.getStorePrice();
            }
        }

        try (ExcelWriter writer = ExcelUtil.getWriter(true)) {
            Sheet sheet = writer.getSheet();
            // 设置每一列的宽度，"序号" 列（0）使用默认宽度即可，其他列根据内容长度设置合适的宽度
            sheet.setColumnWidth(1, 12 * 256);
            sheet.setColumnWidth(2, 36 * 256);
            sheet.setColumnWidth(3, 64 * 256);
            sheet.setColumnWidth(4, 8 * 256);
            sheet.setColumnWidth(5, 10 * 256);
            sheet.setColumnWidth(6, 20 * 256);
            sheet.setColumnWidth(7, 12 * 256);
            sheet.setColumnWidth(8, 12 * 256);
            sheet.setColumnWidth(9, 10 * 256);
            // 写入数据
            writer.write(data, true);

            // 合并订单 ID 相同的行
            int idx = 1;
            for (int i = 0; i < data.size(); i++) {
                Map<String, Object> currentRow = data.get(i);
                // 计算 orderId 相同的订单的开始行和结束行
                int mergeStartRow = i;
                while (i < data.size() - 1 && currentRow.get("订单 ID").equals(data.get(i + 1).get("订单 ID"))) {
                    i++;
                }
                if (mergeStartRow != i) {
                    // 开始和结束的行数不同时，说明这些单元行需要合并
                    // 合并除 "餐品名称", "餐品数量", "餐品总价格" 以外的单元格
                    // 由于 excel 中第一行为标题行，所以合并的开始行数和结束行数都需要 + 1
                    writer.merge(mergeStartRow + 1, i + 1, 0, 0, idx++, false);
                    writer.merge(mergeStartRow + 1, i + 1, 1, 1, currentRow.get("订单日期"), false);
                    writer.merge(mergeStartRow + 1, i + 1, 2, 2, currentRow.get("订单 ID"), false);
                    writer.merge(mergeStartRow + 1, i + 1, 6, 6, currentRow.get("下单时间"), false);
                    writer.merge(mergeStartRow + 1, i + 1, 7, 7, currentRow.get("下单用户"), false);
                    writer.merge(mergeStartRow + 1, i + 1, 8, 8, currentRow.get("用户手机号"), false);
                    writer.merge(mergeStartRow + 1, i + 1, 9, 9, currentRow.get("订单状态"), false);
                } else {
                    // 如果 orderId 不同，则不需要合并，写入正确的序号即可
                    writer.writeCellValue(0, i + 1, idx++);
                }

                if ("售后订单".equals(currentRow.get("订单状态"))) {
                    for (int j = 0; j < 10; j++) {
                        setCellStyle(writer, j, i + 1, IndexedColors.YELLOW.getIndex());
                    }
                }
            }

            Map<String, Object> completedRow = createSummaryRow("汇总", totalCompletedFoodCount, totalCompletedStorePrice / 100.0, "有效订单");
            writer.writeRow(completedRow, false);

            Map<String, Object> afterSaleRow = createSummaryRow(null, totalAfterSaleFoodCount, totalAfterSaleStorePrice / 100.0, "售后订单");
            writer.writeRow(afterSaleRow, false);
            int lastRowIndex = writer.getRowCount() - 1;
            for (int j = 0; j < 10; j++) {
                setCellStyle(writer, j, lastRowIndex, IndexedColors.YELLOW.getIndex());
            }

            String filename = System.currentTimeMillis() + ".xlsx";

            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + filename);
            writer.flush(response.getOutputStream(), true);
        } catch (Exception e) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw new RuntimeException("Error while generating Excel file", e);
        }
    }

    @ApiResponse(responseCode = "200", description = "code 为 200 时，data 字段为包含菜品列表的分页信息")
    @Operation(summary = "17.3 分页展示店铺每天的营收情况", tags = "17. 商铺小程序数据页", operationId = "17.3")
    @PostMapping("/queryStoreDailyData")
    public Result<PaginationResponseVO<StoreDailyDataVO>> queryStoreDailyData(@Valid @RequestBody QueryStoreDailyDataDTO dto) {
        String storeId = dto.getStoreId();
        log.info("/queryStoreDailyData, storeId: {}, phone: {}, pageNo: {}, pageSize: {}, startDate: {}, endDate: {}", storeId, dto.getPhone(), dto.getPageNo(), dto.getPageSize(), dto.getStartDate(), dto.getEndDate());
        if (StringUtils.hasText(storeId)) {
            // 如果前端传递过来的 storeId 不为空
            // 验证前端传递过来的店铺 ID 在数据库中是否存在
            validStoreIdAndPhone(storeId, dto.getPhone());
        } else {
            // 如果前端传递过来的 storeId 为空，则根据店主手机号获取该店铺的 ID
            storeId = merchantStoreManageService.queryStoreIdByMerchantPhone(dto.getPhone());
        }

        int pageNo = dto.getPageNo();
        int pageSize = dto.getPageSize();

        // 开始时间如果未传递，则默认为本月第一天
        String startTime = dto.getStartDate();
        if (dto.getStartDate() == null || dto.getStartDate().isEmpty()) {
            LocalDate today = LocalDate.now();
            LocalDate firstDayOfMonth = today.withDayOfMonth(1);

            startTime = firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }

        // 截至时间设置为当前日期的前一天
        String endTime = dto.getEndDate();
        if (dto.getEndDate() == null || dto.getEndDate().isEmpty()) {
            endTime = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }

        // 分页查询指定店铺每天的营业数据, 多餐功能后，返回的数据是按照 日期标签-用餐时段 分组，因此某一天会返回多条记录，每个用餐时段一条记录
        List<StoreDailyDataDTO> result = orderMapper.queryStoreDailyData(storeId, startTime, endTime);
        List<StoreDailyDataVO> records = new ArrayList<>();

        // 先按照时间分组，得到每天所有用餐时段的记录
        Map<String, List<StoreDailyDataDTO>> dateFlagToOrdersMap = result.stream().collect(Collectors.groupingBy(StoreDailyDataDTO::getDate));

        for (Map.Entry<String, List<StoreDailyDataDTO>> entry : dateFlagToOrdersMap.entrySet()) {
            StoreDailyDataVO storeDailyDataVO = new StoreDailyDataVO();
            int totalOrderCountOfOneDate = 0;
            int todayMoney = 0;
            int todayAfterSaleFoods = 0;
            List<StoreDailyDataVO.OrderDetailByMeal> orderDetailByMeals = new ArrayList<>();
            String dateFlag = entry.getKey();
            // 某一天各个时段的订单详情
            List<StoreDailyDataDTO> orderDetailsOfOneDate = entry.getValue();
            for (StoreDailyDataDTO storeDailyDataDTO : orderDetailsOfOneDate) {
                String mealType = storeDailyDataDTO.getMealType();
                StoreDailyDataVO.OrderDetailByMeal orderDetailByMeal = new StoreDailyDataVO.OrderDetailByMeal();
                orderDetailByMeal.setMealType(mealType);
                orderDetailByMeal.setOrderCount(storeDailyDataDTO.getFoodsOfOneMeal());
                orderDetailByMeals.add(orderDetailByMeal);

                // 将当天每一餐的 订单份数，营业额，售后订单份数进行累加，最终结果为 当天的总订单份数，总营业额，总售后订单份数
                totalOrderCountOfOneDate += storeDailyDataDTO.getFoodsOfOneMeal();
                todayMoney += storeDailyDataDTO.getMoneyOfOneMeal();
                todayAfterSaleFoods += storeDailyDataDTO.getAfterSaleFoodsOfOneMeal();
            }

            // 填充某一天的总营业额，总订单份数，总售后订单份数，当天每一餐的 订单份数
            storeDailyDataVO.setDate(dateFlag);
            storeDailyDataVO.setTodayMoney(todayMoney);
            storeDailyDataVO.setTodayFoods(totalOrderCountOfOneDate);
            storeDailyDataVO.setTodayAfterSaleFoods(todayAfterSaleFoods);
            storeDailyDataVO.setOrderDetailByMeal(orderDetailByMeals);  // 当天每一餐的 订单份数

            records.add(storeDailyDataVO);
        }
        // 先按照日期降序排序
        records.sort(Comparator.comparing(StoreDailyDataVO::getDate));
        // 返回一页数据
        List<StoreDailyDataVO> resultByPage = records.stream().skip((pageNo - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        PaginationResponseVO<StoreDailyDataVO> vo = new PaginationResponseVO<>(records.size(), dto.getPageNo(), resultByPage);
        log.info("/queryStoreDailyData, 接口返回: {}", vo);
        return ResultGenerator.genSuccessResult(vo);
    }

    @ApiResponse(responseCode = "200", description = "code 为 200 时，data 字段为按时间降序排列的有效订单详情列表；code 为 400 时，message 字段返回错误提示信息，此时 data 字段为空")
    @Operation(summary = "17.4 查询有效订单详情", tags = "17. 商铺小程序数据页", operationId = "17.4")
    @PostMapping("/queryStoreDailyOrderDetails")
    public Result<List<StoreDailyOrderDetailVO>> queryStoreDailyOrderDetails(@Valid @RequestBody StoreOrderDetailDTO dto) {
        String storeId = dto.getStoreId();
        log.info("/queryStoreDailyOrderDetails, storeId: {}, phone: {}, date: {}", storeId, dto.getPhone(), dto.getDate());
        if (StringUtils.hasText(storeId)) {
            // 如果前端传递过来的 storeId 不为空
            // 验证前端传递过来的店铺 ID 在数据库中是否存在
            validStoreIdAndPhone(storeId, dto.getPhone());
        } else {
            // 如果前端传递过来的 storeId 为空，则根据店主手机号获取该店铺的 ID
            storeId = merchantStoreManageService.queryStoreIdByMerchantPhone(dto.getPhone());
        }

        List<StoreDailyOrderDetailDTO> dailyOrderDetails = orderMapper.queryStoreCompletedOrderDetailByDateAndStoreId(storeId, dto.getDate());

        List<StoreDailyOrderDetailVO> voList = dailyOrderDetails.stream()
                .map(this::buildStoreDailyOrderDetail)
                // 先按照下单时间降序排列，再按照菜品总价格降序排列
                .sorted(Comparator.comparing(StoreDailyOrderDetailVO::getOrderTime, Comparator.reverseOrder())
                        .thenComparing(StoreDailyOrderDetailVO::getFoodPrice, Comparator.reverseOrder()))
                .collect(Collectors.toList());

        log.info("/queryStoreDailyOrderDetails, 接口返回: {}", voList);
        return ResultGenerator.genSuccessResult(voList);
    }

    private StoreDailyOrderDetailVO buildStoreDailyOrderDetail(StoreDailyOrderDetailDTO dto) {
        String maskedPhone = JxOrderServiceImpl.maskUserPhone(dto.getPhone());
        return new StoreDailyOrderDetailVO(
                dto.getOrderId(),
                dto.getOrderDetailId(),
                dto.getFoodId(),
                dto.getFoodPrintName(),
                dto.getFoodPrice(),
                dto.getFoodNum(),
                dto.getPickUpCode(),
                dto.getUsername(),
                maskedPhone,
                dto.getComment(),
                dto.getDepartmentName(),
                dto.getCompanyName(),
                dto.getOrderTime(),
                dto.getMealType()
        );
    }

    @ApiResponse(responseCode = "200", description = "code 为 200 时，data 字段为按时间降序排列的售后订单详情列表；code 为 400 时，message 字段返回错误提示信息，此时 data 字段为空")
    @Operation(summary = "17.5 查询售后订单详情", tags = "17. 商铺小程序数据页", operationId = "17.5")
    @PostMapping("/queryStoreDailyAfterOrderDetails")
    public Result<List<StoreDailyAfterOrderDetailVO>> queryStoreDailyAfterOrderDetails(@Valid @RequestBody StoreOrderDetailDTO dto) {
        String storeId = dto.getStoreId();
        log.info("/queryStoreDailyAfterOrderDetails, storeId: {}, phone: {}, date: {}", storeId, dto.getPhone(), dto.getDate());
        if (StringUtils.hasText(storeId)) {
            // 如果前端传递过来的 storeId 不为空
            // 验证前端传递过来的店铺 ID 在数据库中是否存在
            validStoreIdAndPhone(storeId, dto.getPhone());
        } else {
            // 如果前端传递过来的 storeId 为空，则根据店主手机号获取该店铺的 ID
            storeId = merchantStoreManageService.queryStoreIdByMerchantPhone(dto.getPhone());
        }

        List<StoreDailyAfterOrderDetailDTO> afterSaleOrderDetails = orderMapper.queryStoreAfterSaleOrderDetailByDateAndStoreId(storeId, dto.getDate());

        List<StoreDailyAfterOrderDetailVO> voList = afterSaleOrderDetails.stream()
                .map(this::buildStoreDailyAfterOrderDetail)
                // 先按照下单时间降序排列，再按照菜品总价格降序排列
                .sorted(Comparator.comparing(StoreDailyAfterOrderDetailVO::getOrderTime, Comparator.reverseOrder())
                        .thenComparing(StoreDailyAfterOrderDetailVO::getFoodPrice, Comparator.reverseOrder()))
                .collect(Collectors.toList());

        log.info("/queryStoreDailyAfterOrderDetails, 接口返回: {}", voList);
        return ResultGenerator.genSuccessResult(voList);
    }

    private StoreDailyAfterOrderDetailVO buildStoreDailyAfterOrderDetail(StoreDailyAfterOrderDetailDTO dto) {
        // TODO: 这里是测试数据，因为目前没有实现售后相关功能，所以暂时使用固定的反馈信息
        String feedBack = dto.getFeedBack();
        if (feedBack == null || feedBack.isEmpty()) {
            feedBack = "无";
        }

        // TODO: 这里是测试数据，因为目前没有实现售后相关功能，所以暂时使用固定的图片
        List<String> images = dto.getImages();
        if (images == null || images.isEmpty()) {
            images = Arrays.asList(
                    "https://jxtc-enterprise.oss-cn-shenzhen.aliyuncs.com/%E4%BA%91%E8%81%9A%E6%99%BA%E8%83%BD/head.jpg",
                    "https://jxtc-enterprise.oss-cn-shenzhen.aliyuncs.com/%E4%BA%91%E8%81%9A%E6%99%BA%E8%83%BD/middle.jpg",
                    "https://jxtc-enterprise.oss-cn-shenzhen.aliyuncs.com/%E4%BA%91%E8%81%9A%E6%99%BA%E8%83%BD/note1.jpg"
            );
        }

        return new StoreDailyAfterOrderDetailVO(
                dto.getOrderId(),
                dto.getOrderDetailId(),
                dto.getOrderDetailId(),
                dto.getFoodPrintName(),
                dto.getFoodPrice(),
                dto.getFoodNum(),
                dto.getPickUpCode(),
                dto.getUsername(),
                dto.getPhone(),
                dto.getComment(),
                dto.getDepartmentName(),
                dto.getCompanyName(),
                dto.getOrderTime(),
                feedBack,
                images
        );
    }

    /**
     * 根据店铺 ID 和手机号，验证店铺 ID 是否存在，店铺不存在时，给出提示信息
     *
     * @param storeId 店铺 ID
     * @param phone   商户手机号
     */
    private void validStoreIdAndPhone(String storeId, String phone) {
        LambdaQueryWrapper<Store> storeQueryWrapper = new LambdaQueryWrapper<Store>()
                .eq(Store::getId, storeId)
                .eq(Store::getMerchantPhone, phone)
                .eq(Store::getDelFlag, false)
                .orderByDesc(Store::getCreateTime);
        if (!storeMapper.exists(storeQueryWrapper)) {
            throw new IllegalArgumentException("ID 为 " + storeId + " 的店铺不存在，请联系管理员排查");
        }
    }

    /**
     * 设置单元格样式
     *
     * @param writer Excel 写入器
     * @param x      单元格的列索引
     * @param y      单元格的行索引
     * @param index  单元格的填充颜色索引
     */
    private void setCellStyle(ExcelWriter writer, int x, int y, short index) {
        CellStyle style = writer.createCellStyle(x, y);
        // 设置填充色
        style.setFillForegroundColor(index);
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        // 解决填充背景没有边框问题
        style.setBorderBottom(BorderStyle.THIN);
        style.setBorderTop(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);
        style.setBorderLeft(BorderStyle.THIN);
        // 设置文本水平居中
        style.setAlignment(HorizontalAlignment.CENTER);
    }

    private Map<String, Object> createRow(ExportStoreDailyDataDTO dto) {
        // 使用 LinkedHashMap 而不是 HashMap 防止标题栏乱序
        Map<String, Object> row = new LinkedHashMap<>();
        row.put("序号", ""); // 需要后续合并单元格时再处理
        row.put("订单日期", dto.getDateFlag());
        row.put("订单 ID", dto.getOrderId());
        row.put("餐品名称", dto.getFoodPrintName());
        row.put("餐品数量", dto.getQuantity());
        row.put("餐品总价格", 1.0 * dto.getStorePrice() / 100);
        row.put("下单时间", dto.getOrderTime());
        row.put("下单用户", dto.getUsername());
        row.put("用户手机号", dto.getPhone());

        String orderStatus = "有效订单";
        if (OrderPaymentStatus.AFTER_SALE.getValue() == dto.getOrderStatus()) {
            orderStatus = "售后订单";
        }
        row.put("订单状态", orderStatus);

        return row;
    }

    private Map<String, Object> createSummaryRow(String rowName, Integer totalQuantity, Double totalAmount, String orderStatus) {
        Map<String, Object> summaryRow = new LinkedHashMap<>();
        summaryRow.put("序号", rowName);
        summaryRow.put("订单日期", "");
        summaryRow.put("订单 ID", "");
        summaryRow.put("餐品名称", "");
        summaryRow.put("餐品数量", totalQuantity);
        summaryRow.put("餐品总价格", totalAmount);
        summaryRow.put("下单时间", "");
        summaryRow.put("下单用户", "");
        summaryRow.put("用户手机号", "");
        summaryRow.put("订单状态", orderStatus);
        return summaryRow;
    }


}
